// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
import QtQuick 1.1
import com.nokia.meego 1.0
import QtMobility.gallery 1.1

Page {
    id: me
   width: 480
   height: 750
    property int picSize: parseInt(parent.width / 3)

    anchors.fill: parent
    orientationLock: PageOrientation.LockPortrait

    Component.onDestruction: {
        console.log("page deleted: " + me);
    }

    Rectangle {
        anchors.fill: parent
        color: "black"
    }

    GridView {
        anchors { top: parent.top; left: parent.left; right: parent.right; bottom: parent.bottom }
        cacheBuffer: 512
        cellHeight: picSize; cellWidth: picSize
        smooth: true

        model: DocumentGalleryModel {
            autoUpdate: true
            properties: [ "url" ]
            rootType: DocumentGallery.Image
        }

        delegate: Rectangle {
            width: picSize; height: picSize
            border { color: "black"; width: 1 }
            color: "black"

            Image {
                anchors.centerIn: parent
                width: picSize - 1; height: picSize - 1

                asynchronous: true
                clip: true
                fillMode: Image.PreserveAspectCrop
                smooth: true
                source: url
                sourceSize.width: width
            }

            MouseArea {
                anchors.fill: parent
                onClicked: {
                    var lastPage = pageStack.find(util.getLastPage);
                    if (lastPage !== null) {
                        lastPage.__selectedImageUrl = url;
                         appWindow.pageStack.pop()
                    }
                }
            }
        }
    }



    tools: ToolBarLayout {
        id: tools
        visible: true

        ToolIcon {
            iconId: "toolbar-back"
            onClicked: {
                 appWindow.pageStack.pop()
            }
        }
    }
}
